//
//  EntrepreneurDetailMessageView.m
//  BigToBig
//
//  Created by yi liu on 16/7/28.
//  Copyright © 2016年 cn.cloudtp. All rights reserved.
//

#import "EntrepreneurDetailMessageView.h"

@implementation EntrepreneurDetailMessageView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews{
    
    // 头像
    self.headImageView = [[UIImageView alloc]initWithFrame:CGRectMake(kScreenWidth / 2 - (kScreenWidth - 20)/12, 5, (kScreenWidth - 20)/6, (kScreenWidth - 20)/6)];
    [self addSubview:self.headImageView];
    self.headImageView.layer.cornerRadius = (kScreenWidth - 20)/12;
    self.headImageView.layer.masksToBounds = YES;
    
    // 分类名
    self.groupLabel = [[UILabel alloc]initWithFrame:CGRectMake(kScreenWidth - self.headImageView.width - 10, self.headImageView.y, self.headImageView.width, self.headImageView.width / 3)];
    _groupLabel.backgroundColor = COLOR_RGBA(0, 228, 161, 1);
    _groupLabel.font = [UIFont systemFontOfSize:12];
    _groupLabel.textAlignment = 1;
    _groupLabel.textColor = [UIColor whiteColor];
    _groupLabel.layer.cornerRadius = 5;
    _groupLabel.layer.masksToBounds = YES;
    [self addSubview:_groupLabel];
    
    // 姓名
    self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, self.headImageView.maxY, kScreenWidth, self.headImageView.width / 3)];
    self.nameLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.nameLabel];
    
    // 职位
    self.jobLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, self.nameLabel.maxY, kScreenWidth, self.nameLabel.height)];
    self.jobLabel.textAlignment = NSTextAlignmentCenter;
    self.jobLabel.textColor = [UIColor lightGrayColor];
    self.jobLabel.font = [UIFont systemFontOfSize:12];
    [self addSubview:self.jobLabel];
    
    
    // 已关注图标
    UIImageView *focusImageView = [[UIImageView alloc]initWithFrame:CGRectMake(kScreenWidth / 2 - kScreenWidth / 9 * 2  , self.jobLabel.maxY, self.headImageView.width / 7 * 2, self.headImageView.width / 7 * 2)];
    focusImageView.image = [UIImage imageNamed:@"guanzhu"];
    [self addSubview:focusImageView];
    
    // 已关注人数
    self.focusLabel = [[UILabel alloc]initWithFrame:CGRectMake(focusImageView.maxX, focusImageView.y, kScreenWidth / 9 * 2 - focusImageView.width, focusImageView.height)];
    self.focusLabel.text = [NSString stringWithFormat:@"  已关注 : 2"];
    self.focusLabel.font = [UIFont systemFontOfSize:10];
    self.focusLabel.textColor = [UIColor lightGrayColor];
    [self addSubview:self.focusLabel];
    
    // 已查看图标
    UIImageView *funsImageView = [[UIImageView alloc]initWithFrame:CGRectMake(kScreenWidth / 2, self.jobLabel.maxY, focusImageView.width, focusImageView.height)];
    funsImageView.image = [UIImage imageNamed:@"fensi"];
    [self addSubview:funsImageView];
    
    // 已查看人数
    self.funsLabel = [[UILabel alloc]initWithFrame:CGRectMake(funsImageView.maxX, funsImageView.y, self.focusLabel.width , self.focusLabel.height)];
    self.funsLabel.text = [NSString stringWithFormat:@"  粉丝 : 3"];
    self.funsLabel.font = [UIFont systemFontOfSize:10];
    self.funsLabel.textColor = [UIColor lightGrayColor];
    [self addSubview:self.funsLabel];
    
    // 个人简介
    UILabel *personalInfoTitle = [[UILabel alloc]initWithFrame:CGRectMake(0, self.funsLabel.maxY + 10, kScreenWidth, self.headImageView.width / 2)];
    personalInfoTitle.text = @"   个人简介";
    personalInfoTitle.font = [UIFont systemFontOfSize:personalInfoTitle.height / 2];
    personalInfoTitle.textAlignment = NSTextAlignmentLeft;
    personalInfoTitle.backgroundColor = COLOR_RGBA(245, 245, 245, 1);
    [self addSubview:personalInfoTitle];
    
    self.personalInfoLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, personalInfoTitle.maxY, kScreenWidth - 40, 100)];
    self.personalInfoLabel.textColor = [UIColor lightGrayColor];
    self.personalInfoLabel.font = [UIFont systemFontOfSize:12];
    [self addSubview:self.personalInfoLabel];
    self.personalInfoLabel.numberOfLines = 0;

}

- (void)layoutSubviews{
    // 计算文字的高度
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14], NSFontAttributeName, nil];
    // 根据文本的内容和文本的字体进行计算高度
    // 参数一:告诉系统,文本显示的最大范围
    CGFloat width = (kScreenWidth - 40);
    CGRect rect = [self.personalInfoLabel.text boundingRectWithSize:CGSizeMake(width, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    rect.origin.x = 20;
    rect.origin.y = self.funsLabel.maxY + 10 + self.headImageView.width/2;

    // 然后把图片的高和文本的高作为返回值返回
    self.personalInfoLabel.frame = rect;
    
//    // 分割线
//    UILabel *lineLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, self.personalInfoLabel.maxY, kScreenWidth, self.height - self.personalInfoLabel.maxY)];
//    lineLabel.backgroundColor = COLOR_RGBA(245, 245, 245, 1);
//    [self addSubview:lineLabel];
    
    self.frame = CGRectMake(0, 0, kScreenWidth, self.personalInfoLabel.maxY);

}


@end
